home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 May / macformat_103_may_2001.iso / Mac OS X Shareware / Fizilla / Chrome / toolkit.jar / content / global / globalOverlay.js < prev    next >
Encoding:
Text File  |  2001-03-26  |  3.7 KB  |  142 lines

  1. function goQuitApplication()
  2. {
  3.   var ObserverService = Components.classes["@mozilla.org/observer-service;1"].getService();
  4.   ObserverService = ObserverService.QueryInterface(Components.interfaces.nsIObserverService);
  5.   if (ObserverService)
  6.   {
  7.     try
  8.     {
  9.       ObserverService.Notify(null, "quit-application", null);
  10.     }
  11.     catch (ex)
  12.     {
  13.       // dump("no observer found \n");
  14.     }
  15.   }
  16.  
  17.   var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService();
  18.   var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator);
  19.   var enumerator = windowManagerInterface.getEnumerator( null );
  20.  
  21.   while ( enumerator.hasMoreElements()  )
  22.   {
  23.     var  windowToClose = enumerator.getNext();
  24.     var domWindow = windowManagerInterface.convertISupportsToDOMWindow( windowToClose );
  25.     domWindow.focus();
  26.     if (!("tryToClose" in domWindow))
  27.     {
  28.       // dump(" window.close \n");
  29.       domWindow.close();
  30.     }
  31.     else
  32.     {
  33.       // dump(" try to close \n" );
  34.       if ( !domWindow.tryToClose() )
  35.         return false;
  36.     }
  37.   };
  38.  
  39.   // call appshell exit
  40.   var appShell = Components.classes['@mozilla.org/appshell/appShellService;1'].getService();
  41.   appShell = appShell.QueryInterface( Components.interfaces.nsIAppShellService );
  42.   appShell.Quit();
  43.   return true;
  44. }
  45.  
  46. //
  47. // Command Updater functions
  48. //
  49. function goUpdateCommand(command)
  50. {
  51.   try {
  52.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  53.  
  54.     var enabled = false;
  55.  
  56.     if ( controller )
  57.       enabled = controller.isCommandEnabled(command);
  58.  
  59.     goSetCommandEnabled(command, enabled);
  60.   }
  61.   catch (e) {
  62.     dump("An error occurred updating the "+command+" command\n");
  63.   }
  64. }
  65.  
  66. function goDoCommand(command)
  67. {
  68.   try {
  69.     var controller = top.document.commandDispatcher.getControllerForCommand(command);
  70.     if ( controller && controller.isCommandEnabled(command))
  71.       controller.doCommand(command);
  72.   }
  73.   catch (e) {
  74.     dump("An error occurred executing the "+command+" command\n");
  75.   }
  76. }
  77.  
  78.  
  79. function goSetCommandEnabled(id, enabled)
  80. {
  81.   var node = document.getElementById(id);
  82.  
  83.   if ( node )
  84.   {
  85.     if ( enabled )
  86.       node.removeAttribute("disabled");
  87.     else
  88.       node.setAttribute('disabled', 'true');
  89.   }
  90. }
  91.  
  92. function goSetMenuValue(command, labelAttribute)
  93. {
  94.   var commandNode = top.document.getElementById(command);
  95.   if ( commandNode )
  96.   {
  97.     var label = commandNode.getAttribute(labelAttribute);
  98.     if ( label )
  99.       commandNode.setAttribute('label', label);
  100.   }
  101. }
  102.  
  103. // this function is used to inform all the controllers attached to a node that an event has occurred
  104. // (e.g. the tree controllers need to be informed of blur events so that they can change some of the
  105. // menu items back to their default values)
  106. function goOnEvent(node, event)
  107. {
  108.   var numControllers = node.controllers.getControllerCount();
  109.   var controller;
  110.  
  111.   for ( var controllerIndex = 0; controllerIndex < numControllers; controllerIndex++ )
  112.   {
  113.     controller = node.controllers.getControllerAt(controllerIndex);
  114.     if ( controller )
  115.       controller.onEvent(event);
  116.   }
  117. }
  118.  
  119. function setTooltipText(aID, aTooltipText)
  120. {
  121.   var element = document.getElementById(aID);
  122.   if (element)
  123.     element.setAttribute("tooltiptext", aTooltipText);
  124. }
  125.  
  126. function FillInTooltip ( tipElement )
  127. {
  128.   var retVal = false;
  129.   var textNode = document.getElementById("TOOLTIP-tooltipText");
  130.   while (textNode.hasChildNodes())
  131.     textNode.removeChild(textNode.firstChild);
  132.   if (textNode) {
  133.     var tipText = tipElement.getAttribute("tooltiptext");
  134.     if (tipText) {
  135.       var node = document.createTextNode(tipText);
  136.       textNode.appendChild(node);
  137.       retVal = true;
  138.     }
  139.   }
  140.   return retVal;
  141. }
  142.